<?php
/**
 *  Episode::orderBy('created_at')->chunk(5000, function ($episode) use ($needles, $array_inc) {
 *        foreach ($episode as $ep) {
 *           //防止重写ep的名称
 *           $ep->timestamps = false;
 *           $ep->save();
 *           echo "$name \n\r";
 *       }
 *  });
 * @param $episode_raw_name
 * @return string 过滤episode的原始名称
 */
function filterEpisodeRawName($episode_raw_name): string
{

    $trash_pattern = $pattern = [
        '#【720P高清】#i',
    ];
    $episode_raw_name = preg_replace($trash_pattern, '', $episode_raw_name);

    $pattern = [
        '#(?<=e\d\d).*#i',
        '#(?<=ep\d\d).*#i',
        '#(\s|\.|\[eztv\])+#',
        '#\bWEB\b.*#',
        '#hdtv.*#i',
        '#1080.*#i',
        '#1024.*#i',
        '#720.*#i',
        '#\[#i',
        '#\]#i',

    ];
    $episode_raw_name = preg_replace($pattern, ' ', $episode_raw_name);

    $episode_raw_name = trim($episode_raw_name);
    return $episode_raw_name;

}

//https://stackoverflow.com/questions/5517255/remove-style-attribute-from-html-tags
//在js代码里面为抓取的正文添加 class
function removeStyleAttribute($html)
{
    return preg_replace('/(<[^>]+) style=".*?"/i', '$1', $html);
}